#include "MyDialogUI.h"
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QFrame>

MyDialogUI::MyDialogUI(QWidget *parent)
        : QWidget(parent)
{
    setWindowFlags(Qt::FramelessWindowHint);
    // 左侧区域（label2）
    label2 = new QLabel("左侧内容");
    label2->setAlignment(Qt::AlignCenter);
    label2->setStyleSheet("background-color: lightblue;");

    QScrollArea *scrollLeft = new QScrollArea;
    scrollLeft->setWidget(label2);
    scrollLeft->setWidgetResizable(true);

    // 中间按钮区域
    QWidget *centerWidget = new QWidget;
    QVBoxLayout *centerLayout = new QVBoxLayout(centerWidget);
    btn = new QPushButton("按钮");
    centerLayout->addWidget(btn);
    centerLayout->addStretch();

    QScrollArea *scrollCenter = new QScrollArea;
    scrollCenter->setWidget(centerWidget);
    scrollCenter->setWidgetResizable(true);

    // 右侧区域（label3）
    label3 = new QLabel("右侧内容");
    label3->setAlignment(Qt::AlignCenter);
    label3->setStyleSheet("background-color: lightgreen;");

    QScrollArea *scrollRight = new QScrollArea;
    scrollRight->setWidget(label3);
    scrollRight->setWidgetResizable(true);

    // 使用 QSplitter
    QSplitter *splitter = new QSplitter(Qt::Horizontal);
    splitter->addWidget(scrollLeft);
    splitter->addWidget(scrollCenter);
    splitter->addWidget(scrollRight);

    // 设置比例（40% : 40% : 20%）
    splitter->setStretchFactor(0, 4);
    splitter->setStretchFactor(1, 2);
    splitter->setStretchFactor(2, 4);

    // 最外层布局
    QHBoxLayout *mainLayout = new QHBoxLayout(this);
    mainLayout->addWidget(splitter);
    setLayout(mainLayout);

    setWindowTitle("MyDialogUI - QSplitter + QScrollArea");
    resize(800, 500);
}
